l = input ()
 
if len(str(l)) != 4:
    print(0)
else:
    u = False
    for length in range(4, 0, -1):
        if u:
            break
        for i in range(4 - length + 1):
            i = int(str(l)[i:i+l])
            if i < 2:
                continue
            for j in range(2, int(i**0.5) + 1):
                if i % j == 0:
                    break
            else:
                print(i)
                u = True
                break
    if not u:
        print(0)
